package com.shop.cloud.service.hongfu.impl;

import java.sql.Timestamp;

import com.shop.cloud.dao.hongfu.LogDao;
import com.shop.cloud.domain.hongfu.Log;
import com.shop.cloud.service.hongfu.ILogService;
import com.shop.cloud.util.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shop.cloud.common.mybatis.BaseService;
import com.shop.cloud.common.mybatis.MybatisDao;

/**
 * shop
 */
@Service("logService")
public class LogService extends BaseService<Log> implements ILogService{

	
	@Autowired
	private LogDao logDao;

	@Override
	public MybatisDao<Log> getEntityDao() {
		// TODO Auto-generated method stub
		return logDao;
	}


	@Override
	public Integer addLog(Long userId , Integer state , String content) {
		Log log = new Log();
		log.setUserId(userId);
		log.setState(state);
		log.setContent(content);
		Timestamp time = new Timestamp(System.currentTimeMillis()); 
		log.setCreateTime(time);
		logDao.insert(log);
		return 1;
	}
	
	@Override
	public Page<Log> pageLog(Log log) {
		log.setPageSize((log.getPageSize_()==null?20:log.getPageSize_()));
		long count = logDao.findLogCount(log);
		Page<Log> page = new Page<Log>(log.getPageIndex_(), log.getPageSize_());
		page.setData(logDao.findLog(log));
		page.setTotalCount(count);
		return page;
	}

}